package cn.iocoder.yudao.module.ems.dal.mysql.spares;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.ems.controller.admin.spares.vo.SparesListReqVO;
import cn.iocoder.yudao.module.ems.controller.admin.warehousing.vo.WarehousingInfoBaseVO;
import cn.iocoder.yudao.module.ems.controller.admin.warehousing.vo.WarehousingInfoCreateReqVO;
import cn.iocoder.yudao.module.ems.dal.dataobject.spares.SparesDO;
import cn.iocoder.yudao.module.ems.dal.dataobject.spares.SparesDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.ems.controller.admin.spares.vo.*;

/**
 * 备品备件 Mapper
 *
 * @author dason
 */
@Mapper
public interface SparesMapper extends BaseMapperX<SparesDO> {

    default PageResult<SparesDO> selectPage(SparesPageReqVO reqVO, Collection<Long> classificationIds) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SparesDO>()
                .eqIfPresent(SparesDO::getItemNo, reqVO.getItemNo())
                .likeIfPresent(SparesDO::getName, reqVO.getName())
                .eqIfPresent(SparesDO::getSpecification, reqVO.getSpecification())
                .eqIfPresent(SparesDO::getLabelingCode, reqVO.getLabelingCode())
                .eqIfPresent(SparesDO::getStatus, reqVO.getStatus())
                .inIfPresent(SparesDO::getClassificationId, classificationIds)
                .orderByDesc(SparesDO::getId));
    }

    default List<SparesDO> selectList(SparesExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<SparesDO>()
                .eqIfPresent(SparesDO::getItemNo, reqVO.getItemNo())
                .likeIfPresent(SparesDO::getName, reqVO.getName())
                .eqIfPresent(SparesDO::getSpecification, reqVO.getSpecification())
                .eqIfPresent(SparesDO::getLabelingCode, reqVO.getLabelingCode())
                .eqIfPresent(SparesDO::getStatus, reqVO.getStatus())
                .orderByDesc(SparesDO::getId));
    }

    default SparesDO selectByItemNo(String itemNo) {
        return selectOne(new LambdaQueryWrapper<SparesDO>().eq(SparesDO::getItemNo, itemNo));
    }

    /***
     *
     * @param entity
     * @param number
     */
    default void updateAmountByInfo(SparesDO entity, Integer number) {
        Integer amout = entity.getAmount();
        Integer newAmout = amout + number;
        entity.setAmount(newAmout);
        updateById(entity);
    }


    default List<SparesDO> selectList(SparesListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<SparesDO>()
                .likeIfPresent(SparesDO::getName, reqVO.getName())
                .eqIfPresent(SparesDO::getStatus, reqVO.getStatus()));
    }

}
